<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<script src="./crypto.js"></script>
<!--<script src="./aeswh.js"></script>-->
<body>
<script>
  var key = CryptoJS.enc.Utf8.parse("2021-11-11 12:54:28");
  var plaintText = '{"key1":"xxx"}'; // 明文
  var encryptedData = CryptoJS.AES.encrypt(plaintText, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  console.log("加密前："+plaintText);
  console.log("加密后："+encryptedData);

  encryptedData = encryptedData.ciphertext.toString();
  console.log("encryptedData:"+encryptedData);
  var encryptedHexStr = CryptoJS.enc.Hex.parse(encryptedData);
    console.log("encryptedHexStr:"+encryptedHexStr);
  var encryptedBase64Str = CryptoJS.enc.Base64.stringify(encryptedHexStr);
   console.log("encryptedBase64Str:"+encryptedBase64Str);
  var decryptedData = CryptoJS.AES.decrypt(encryptedBase64Str, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
   console.log("decryptedData:"+decryptedData);
  var decryptedStr = CryptoJS.enc.Utf8.stringify(decryptedData).toString();
  console.log("解密后:"+decryptedStr);

  //解密方式2
  var o = "2021-11-11 12:54:28";
  o = CryptoJS.enc.Utf8.parse(o);
  var message = "K1eJX6qvfkcoBNRXE1Vd/r6M6kq37twh0iM4HyAQs2R/cA9eJAAPf8Ec9/rSPhNs";
var encryptedHexStr = CryptoJS.enc.Hex.parse(message);
    console.log("encryptedHexStr:"+encryptedHexStr);
  var encryptedBase64Str = CryptoJS.enc.Base64.stringify(encryptedHexStr);
   console.log("encryptedBase64Str:"+encryptedBase64Str);
  var decryptedData = CryptoJS.AES.decrypt(encryptedBase64Str, o, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  console.log("decryptedData:"+decryptedData);
  console.log("解密方式2:"+CryptoJS.enc.Utf8.stringify(decryptedData).toString());

</script>
</body>
</html>


